﻿
function writeid(id,porttype,flag,iIndex)
{
//    alert(iIndex);
    
    var table = document.getElementById("DataGridMess");
    var test = document.getElementById("DataGridMess").getElementsByTagName("input");
        
    aid = document.getElementById("hdids");
    if(porttype != "")
    {
        atype = document.getElementById("hidporttype");
    }

    if(aid.value == "" || aid.value == "0")
    {
        aid.value += ",";
        if(porttype != "")
        {
            atype.value += ",";
         }
    }
    if(flag == true)
    {
        len = test.length;
        for(r=0;r<len;r++)
        {
            if(test[r].checked)
            {
                aid.value += id + ",";
                if(porttype != "")
                {
                    atype.value += porttype + ",";
                }
                break;
            }
        }
        
    }
    else
    {
        aid.value = aid.value.replace(new RegExp("," + id + ",", 'g'), ",");
        if(porttype != "")
        {
            atype.value = atype.value.replace(new RegExp("," + porttype + ",", 'g'), ",");
        }
    }
}
function deledata(str)
{
    objs = document.getElementById("tblInfo").getElementsByTagName("input");
    len=objs.length;
    ids="0";
    for(i=1;i<len;i++)
    {
        ids += objs[i].checked?objs[i].id.replace("cb_",","):"";
    }
    if(ids=="0")
    {
        alert("请选择数据行！");
        return false;
    }
    document.getElementById("hdids").value=ids;
    str=str==null?"删除选定行？":str;
    if(!confirm(str))
    {
        return false;
    }
    return true;
}

function deledataNew(str)
{
    num=0;

    var table = document.getElementById("DataGridMess");
    var test = document.getElementById("DataGridMess").getElementsByTagName("input");

    len = test.length;
    for(r=0;r<len;r++)
    {
        if(test[r].checked)
        {
            num++
        }
    }
    if(num<1)
    {
        alert("请选择数据行！");
        return false;
    }
//    document.getElementById("hdids").value=ids;
    str=str==null?"删除选定行？":str;
    if(!confirm(str))
    {
        return false;
    }
    return true;
}

function editdata(surl)
{
    objs = document.getElementById("tblInfo").getElementsByTagName("input");
    len=objs.length;
    num=0;
    id=0;
    for(i=1;i<len;i++)
    {
        if(objs[i].checked)
       {num++;id=objs[i].id.replace("cb_","");}
    }
    document.getElementById("hdids").value=id;
    if(num!=1)
    {
        alert("请选择且只选择一条数据！");
        return false;
    }
    alert(surl);
    if(surl!=null)
    {
        openWindow(surl+"?id="+id);
        return false;
        
    }
    return true;
}

function editdataNew(surl)
{
    num=0;
    id=0;
    porttype = "";

    var table = document.getElementById("DataGridMess");
    var test = document.getElementById("DataGridMess").getElementsByTagName("input");

    len = test.length;
    for(r=0;r<len;r++)
    {
        if(test[r].checked)
        {
            num++
        }
    }
    if(num!=1)
    {
        alert("请选择且只选择一条数据！");
        return false;
    }
    id = document.getElementById("hdids").value;
    id = id.replace(new RegExp(",", 'g'), "");
    url = surl+"?id="+id;
    if(document.getElementById("hidporttype") != null)
    {
        porttype = document.getElementById("hidporttype").value;
        porttype = porttype.replace(new RegExp(",", 'g'), "");
        url = url + "&porttype=" + porttype;
    }
//    alert(id + "\r\n" + porttype);
    if(surl!=null)
    {
        openWindow(url);
        return false;
        
    }
    return true;
}

function audidata(surl)
{
    objs = document.getElementById("tblInfo").getElementsByTagName("input");
    len=objs.length;
    num=0;
    id=0;
    for(i=1;i<len;i++)
    {
        if(objs[i].checked)
       {num++;id=objs[i].id.replace("cb_","");}
    }
    document.getElementById("hdids").value=id;
    if(num!=1)
    {
        alert("请选择且只选择一条数据！");
        return false;
    }
    if(surl!=null)
    {
        openWindow(surl+"?audi=1&noedit=1&id="+id);
        return false;
        
    }
    return true;
}

function goaddurl(surl)
{
    if(surl!=null)
    {
        openWindow(surl);
        return false;
    }
    return true;
}

function checkAll(obj)
{   objs = document.getElementById("tblInfo").getElementsByTagName("input");
    len=objs.length;
    num=0;
    for(i=1;i<len;i++)
    {
        objs[i].checked=obj.checked;
    }
}

function trclick(tr)
{	    
    for(i=1;i<tr.parentNode.parentNode.rows.length;i++)
    {
        if(tr.parentNode.parentNode.rows[i].getAttribute("class")=="trselect")
        {
            classname=i%2==0?"trtwo":"trtree";
            tr.parentNode.parentNode.rows[i].setAttribute("class",classname);
            tr.parentNode.parentNode.rows[i].setAttribute("className",classname);
        }
    }
    tr.setAttribute("class","trselect");
    tr.setAttribute("className","trselect");
}
function backreflesh()
{
if(window.parent.document.getElementById("inLeftFrame")!=null)
{
window.parent.document.getElementById("inLeftFrame").contentWindow.location=window.parent.document.getElementById("inLeftFrame").contentWindow.location.toString();
window.location=window.location.toString();
}
else
{
window.location=window.location.toString();
}
}

function returnmain()
{
if(window.parent.parent!=null)
{
    window.parent.parent.history.back(1);
}
else
{
window.parent.history.back(1);
}
}

function openWindow(surl)
{
window.open(surl,"editwindow","toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no"); 
}